package com.example.chatroom.configuration;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

@Configuration
public class MyConfiguration implements WebMvcConfigurer {
    @Resource
    private LoginInterceptor loginInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor)
                .addPathPatterns("/**")                // 拦截所有的url
                .excludePathPatterns("/login.html")    // 排除登录界面
                .excludePathPatterns("/register.html") // 排除注册页
                .excludePathPatterns("/css/**")        // 排除所有css样式文件
                .excludePathPatterns("/avatars/**")    // 排除所有头像图片文件
                .excludePathPatterns("/img/**")        // 排除所有的图片文件
                .excludePathPatterns("/js/**")         // 排除所有的js样式文件
                .excludePathPatterns("/user/register")
                .excludePathPatterns("/user/login")
        ;
    }
}
